<template>
  <div>
    <table class="table table-bordered">
      <tr>
        <td>项目ID</td>
        <td>
          <input type="text" v-model="sdata.ST_Id" />
        </td>
      </tr>
      <tr>
        <td>投资项目名称</td>
        <td>
          <input type="text" v-model="sdata.ST_Name" />
        </td>
      </tr>
      <tr>
        <td>总额度</td>
        <td>
          <input type="text" v-model="sdata.ST_Zong" />
        </td>
      </tr>
      <tr>
        <td>已投金额</td>
        <td>
          <input type="text" v-model="sdata.ST_Yi" />
        </td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="添加投资" @click="add" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
let router = useRouter();
let route = useRoute();
import { useStore } from '../../store/user';
let user = useStore();

let data = reactive({
  sdata: {
    ST_Id: '',
    ST_Name: '',
    ST_Zong: '',
    ST_Yi: '',
  },
});
let { sdata } = toRefs(data);

const add = () => {
  if (sdata.value.ST_Id == '') {
    alert('项目ID不能为空');
    return;
  }
  if (sdata.value.ST_Name == '') {
    alert('投资项目名称不能为空');
    return;
  }
  if (isNaN(Number(sdata.value.ST_Zong)) == true) {
    alert('总额度必须输入数字类型');
    return;
  }
  if (isNaN(Number(sdata.value.ST_Yi)) == true) {
    alert('已投金额必须输入数字类型');
    return;
  }
  if (Number(sdata.value.ST_Yi) < 0) {
    alert('已投金额必须大于0');
    return;
  }
  axios({
    url: 'http://localhost:64124/api/Text03/PostAddTouZi',
    method: 'post',
    data: sdata.value,
  })
    .then((res) => {
      console.log(res);
      if (res.data.data > 0) {
        alert('添加成功');
        router.push('/adminsanshow03');
      } else if (res.data.data == -10) {
        alert('用户名重复');
        return;
      } else {
        alert('添加失败');
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
